﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using WebApi.Core.IRepository;
using WebApi.Core.IRepository.Base;
using WebApi.Core.IService;
using WebApi.Core.Model.Entity;
using WebApi.Core.Service.Base;

namespace WebApi.Core.Service
{
    public class RoleModuleService : BaseServices<RoleModuleEntity>, IRoleModuleService
    {
        private readonly IRoleRepository _roleDal;
        private readonly IModuleRepository _moduleDal;
        private readonly IRoleModuleRepository _roleModuleDal;

        public RoleModuleService(IBaseRepository<RoleModuleEntity> _baseRepository,
            IRoleRepository _roleRepository,
            IModuleRepository _moduleRepository,
            IRoleModuleRepository _roleModuleRepository) 
            :base(_baseRepository)
        {
            _roleDal = _roleRepository;
            _moduleDal = _moduleRepository;
            _roleModuleDal = _roleModuleRepository;
        }

        //public async Task<int> GetCount()
        //{
        //    return await _userDal.GetCount();
        //}

        /// <summary>
        /// 获取全部 角色接口(按钮)关系数据 
        /// </summary>
        /// <returns></returns>
        //[Caching(AbsoluteExpiration = 10)]
        public async Task<List<RoleModuleEntity>> GetRoleModule()
        {
            var roleModulePermissions = await _roleModuleDal.Query();
            if (roleModulePermissions.Count > 0)
            {
                foreach (var item in roleModulePermissions)
                {
                    item.Role = await _roleDal.QueryByID(item.RoleId);
                    item.Module = await _moduleDal.QueryByID(item.ModuleId);
                }

            }
            return roleModulePermissions;
        }

        


    }
}
